1 /*
2 * Copyright (C) 2007 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.common.base;
18
19 import java.lang.ref.PhantomReference;
20 import java.lang.ref.ReferenceQueue;
21
22 /**
23 * Phantom reference with a {@code finalizeReferent()} method which a background thread invokes
24 * after the garbage collector reclaims the referent. This is a simpler alternative to using a
25 * {@link ReferenceQueue}.
26 *
27 * <p>Unlike a normal phantom reference, this reference will be cleared automatically.
28 *
29 * @author Bob Lee
30 * @since 2.0 (imported from Google Collections Library)
31 */
32 public abstract class FinalizablePhantomReference<T> extends PhantomReference<T>
33 implements FinalizableReference {
34 /**
35 * Constructs a new finalizable phantom reference.
36 *
37 * @param referent to phantom reference
38 * @param queue that should finalize the referent
39 */
40 protected FinalizablePhantomReference(T referent, FinalizableReferenceQueue queue) {
41 super(referent, queue.queue);
42 queue.cleanUp();
43 }
44 }